// custom-tab-bar/index.js
import {storeBindingsBehavior} from 'mobx-miniprogram-bindings'
import {store} from '../store/store'
Component({
  options:{
    styleIsolation:'shared'
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      active:'activeTabBarIndex'
    },
    actions: {
      updateActive: 'updateActiveTabBarIndex'
    } 
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    "list": [
      {
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "/images/TabBar/home1.png",
        "selectedIconPath": "/images/TabBar/home.png"
      },
      {
        "pagePath": "/pages/treeinfo/treeinfo",
        "text": "树信息",
        "iconPath": "/images/TabBar/tree1.png",
        "selectedIconPath": "/images/TabBar/tree.png"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/images/TabBar/my.png",
        "selectedIconPath": "/images/TabBar/me.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail }),
      this.updateActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})
